﻿<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<OneDollarStore.SerialProduct>>" %>

<asp:Content ID="TitleContent" ContentPlaceHolderID="TitleContent" runat="server">
    Báo giá
</asp:Content>

<asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" runat="server">
    <div class="right">
        <h1 style="text-align:center; margin-left:5px; color:Green">Báo giá</h1>
        <br />
        <div style="margin-left:5px; font-size:15px">
            <table border="1" frame="box" rules="all"  style="width:98.6%; text-align:center; line-height:30px">
                <tr style="font-size:18px; color:Purple">
                    <th>Danh Mục</th>
                    <th>Tên</th>
                    <th>Giá</th>
                </tr>
                <% int laptopCount = 0;
                   int desktopCount = 0;
                   int mainboardCount = 0;
                   int cpuCount = 0;
                   int ramCount = 0;
                   int hddCount = 0;
                   int vgaCount = 0;
                   foreach (var item in Model)
                   {
                       if (item.Category.Name == "Laptop")
                       {
                           laptopCount++;
                       }
                       else if (item.Category.Name == "Desktop")
                       {
                           desktopCount++;
                       }
                       else if (item.Category.Name == "Mainboard")
                       {
                           mainboardCount++;
                       }
                       else if (item.Category.Name == "CPU")
                       {
                           cpuCount++;
                       }
                       else if (item.Category.Name == "RAM")
                       {
                           ramCount++;
                       }
                       else if (item.Category.Name == "HDD")
                       {
                           hddCount++;
                       }
                       else if (item.Category.Name == "VGA")
                       {
                           vgaCount++;
                       }
                   }
                   for (int i = 0; i < Model.Count(); i++)
                   { %>
                    <tr>
                        <% if (i == 0)
                           { %>
                            <td style="color:Teal; font-weight:bold" rowspan="<%= cpuCount %>"><%= Html.ActionLink("CPU", "Category", "Product", new { id = "CPU" }, new { }) %></td>
                        <% }
                           if (i == cpuCount)
                           { %>
                            <td style="color:Teal; font-weight:bold" rowspan="<%= desktopCount %>"><%= Html.ActionLink("Desktop", "Category", "Product", new { id = "Desktop" }, new { })%></td>
                        <% }
                           if (i == cpuCount + desktopCount)
                           { %>
                            <td style="color:Teal; font-weight:bold" rowspan="<%= hddCount %>"><%= Html.ActionLink("HDD", "Category", "Product", new { id = "HDD" }, new { })%></td>
                        <% }
                           if (i == cpuCount + desktopCount + hddCount)
                           { %>
                            <td style="color:Teal; font-weight:bold" rowspan="<%= laptopCount %>"><%= Html.ActionLink("Laptop", "Category", "Product", new { id = "Laptop" }, new { })%></td>
                        <% }
                           if (i == cpuCount + desktopCount + hddCount + laptopCount)
                           { %>
                            <td style="color:Teal; font-weight:bold" rowspan="<%= mainboardCount %>"><%= Html.ActionLink("Mainboard", "Category", "Product", new { id = "Mainboard" }, new { })%></td>
                        <% }
                           if (i == cpuCount + desktopCount + hddCount + laptopCount + mainboardCount)
                           { %>
                            <td style="color:Teal; font-weight:bold" rowspan="<%= ramCount %>"><%= Html.ActionLink("RAM", "Category", "Product", new { id = "RAM" }, new { })%></td>
                        <% }
                           if (i == cpuCount + desktopCount + hddCount + laptopCount + mainboardCount + ramCount)
                           { %>
                            <td style="color:Teal; font-weight:bold" rowspan="<%= vgaCount %>"><%= Html.ActionLink("VGA", "Category", "Product", new { id = "VGA" }, new { })%></td>
                        <% } %>
                        <td><%= Ajax.ActionLink(Model.ElementAt(i).Name, "Details", "Product", new { id = Model.ElementAt(i).SerialProductID }, new AjaxOptions { UpdateTargetId = "details", OnSuccess = "hideLoading" }) %></td>
                        <% if (String.IsNullOrEmpty(Model.ElementAt(i).PromotionPrice.ToString()) ||
                               ((!String.IsNullOrEmpty(Model.ElementAt(i).PromotionPrice.ToString())) && (DateTime.Today > Model.ElementAt(i).PromotionEndDate)))
                           { %>
                            <td><%= Model.ElementAt(i).RetailPrice%></td>
                        <% }
                           else
                           { %>
                            <td style="text-decoration:underline"><%= Model.ElementAt(i).PromotionPrice%></td>
                        <% } %>
                    </tr>
                <% } %>
            </table>
        </div>
    </div>
</asp:Content>